/* void switch_cpu(cpu_state_t **from, cpu_state_t **to) */
.align
.global switch_cpu

switch_cpu:
    CMP R0, #0             /* if no initial process start first process */
    BEQ do_start_process

    STMFD   SP!, {r14}     /* save process state onto stack */
    STMFD   SP!, {r0-r14}^
    MRS     r2, spsr
    STMFD   SP!, {r2}

    /* process->cpu_state = SP */
    STR     SP, [r0]

do_start_process:
    /* switch to other process */
    LDR     SP, [r1] /* SP = next_process->cpu_state */

    /* restore context */
    LDMFD   SP!, {r2}
    MSR     spsr, r2
    LDMFD   SP!, {r0-r14}^
    LDMFD   SP!, {pc}

/* used for process start */
.align
.global INIT_JUMP_PROCESS

INIT_JUMP_PROCESS:
    LDMFD   SP!, {pc}^
    MOV R0,R0           /* NOOP 'wirkungsloser' Befehl eingefuegt */

